﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Calibration.CApCalibrationPair
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.ComponentModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.Calibration;

public class CApCalibrationPair : INotifyPropertyChanged
{
  private ITxLocatableObject _VirtualPoint;
  private TxTransformation _VirtualLocation;
  private ITxLocatableObject _ActualPoint;
  private TxTransformation _ActualLocation;
  private CApCalibrationTransformation _Parent;
  private bool _IsActive = true;
  private TxTransformation _RelativeToTransformation;
  private double _DistanceBefore;
  private double _DistanceAfter;

  public ITxLocatableObject VirtualPoint
  {
    get => this._VirtualPoint;
    set => this._VirtualPoint = value;
  }

  public TxTransformation VirtualLocation
  {
    get => this._VirtualLocation;
    set => this._VirtualLocation = value;
  }

  public ITxLocatableObject ActualPoint
  {
    get => this._ActualPoint;
    set => this._ActualPoint = value;
  }

  public TxTransformation ActualLocation
  {
    get => this._ActualLocation;
    set => this._ActualLocation = value;
  }

  public CApCalibrationTransformation Parent
  {
    get => this._Parent;
    set => this._Parent = value;
  }

  public bool IsActive
  {
    get => this._IsActive;
    set => this._IsActive = value;
  }

  public bool IsActivePropertyChanged
  {
    get => this._IsActive;
    set
    {
      if (this._IsActive == value)
        return;
      this._IsActive = value;
      if (this.Parent != null)
        this.Parent.Calibrate();
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs(nameof (IsActivePropertyChanged)));
    }
  }

  public TxTransformation VirtualRelativeLocation
  {
    get
    {
      TxTransformation relativeLocation = new TxTransformation();
      if (this.VirtualPoint != null)
        relativeLocation = !TxTransformation.op_Inequality(this._RelativeToTransformation, (TxTransformation) null) ? this.VirtualLocation : TxTransformation.op_Multiply(this._RelativeToTransformation.Inverse, this.VirtualLocation);
      return relativeLocation;
    }
  }

  public TxTransformation ActualRelativeLocation
  {
    get
    {
      TxTransformation relativeLocation = new TxTransformation();
      if (this.ActualPoint != null)
        relativeLocation = !TxTransformation.op_Inequality(this._RelativeToTransformation, (TxTransformation) null) ? this.ActualLocation : TxTransformation.op_Multiply(this._RelativeToTransformation.Inverse, this.ActualLocation);
      return relativeLocation;
    }
  }

  public TxTransformation RelativeToTransformation
  {
    get => this._RelativeToTransformation;
    set
    {
      this._RelativeToTransformation = value;
      if (this.PropertyChanged != null)
        this.PropertyChanged((object) this, new PropertyChangedEventArgs("VirtualRelativeLocation"));
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs("ActualRelativeLocation"));
    }
  }

  public double DistanceBefore
  {
    get => this._DistanceBefore;
    set
    {
      this._DistanceBefore = value;
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs(nameof (DistanceBefore)));
    }
  }

  public double DistanceAfter
  {
    get => this._DistanceAfter;
    set
    {
      this._DistanceAfter = value;
      if (this.PropertyChanged == null)
        return;
      this.PropertyChanged((object) this, new PropertyChangedEventArgs(nameof (DistanceAfter)));
    }
  }

  public double Distance(TxTransformation Trans)
  {
    TxVector txVector = TxVector.op_Subtraction(this.ActualRelativeLocation.Translation, TxTransformation.op_Multiply(Trans, this.VirtualRelativeLocation).Translation);
    return Math.Sqrt(Math.Pow(txVector.X, 2.0) + Math.Pow(txVector.Y, 2.0) + Math.Pow(txVector.Z, 2.0));
  }

  public void Clone(CApCalibrationPair origin)
  {
    this._ActualPoint = origin._ActualPoint;
    this._ActualLocation = origin._ActualLocation;
    this._DistanceAfter = origin._DistanceAfter;
    this._DistanceBefore = origin._DistanceBefore;
    this._IsActive = origin._IsActive;
    this._Parent = origin._Parent;
    this._RelativeToTransformation = origin._RelativeToTransformation;
    this._VirtualPoint = origin._VirtualPoint;
    this._VirtualLocation = origin._VirtualLocation;
  }

  public event PropertyChangedEventHandler PropertyChanged;
}
